<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="com.qfedu.sem.dto.BugDto" %>
<%@page import="com.qfedu.sem.dto.BugLogDto" %>
<%@page import="com.qfedu.sem.dto.BugVersionDto" %>
<%@page import="wo.bsys.vo.WoUser" %>
<%@page import="wo.bsys.util.BSysConstant" %>
<%@page import="java.util.List" %>
<%
	BugDto bug = (BugDto)request.getAttribute("bug");
	List<BugVersionDto> versions = (List<BugVersionDto>)request.getAttribute ("versions");
	WoUser u = (WoUser) request.getSession().getAttribute(BSysConstant.SESSION_USER);
%>
<div id="page-wrapper">
	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">故障流程图</div>
				<div class="panel-body">
					<img alt="" src="${pageContext.request.contextPath}/sb-admin2/images/bug/bug-<%=bug.getCurrentNode()%>.png">
				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">故障信息</div>
				<div class="panel-body">
					<table>
						<tr><td width="100">ID</td><td><%=bug.getId()%></td></tr>
						<tr><td width="100">标题</td><td><%=bug.getTitle()%></td></tr>
						<tr><td width="100">描述</td><td><%=bug.getDescription()%></td></tr>
						<tr><td width="100">项目</td><td><%=bug.getProjectName()%></td></tr>
						<tr><td width="100">版本</td><td><%=bug.getVersionNo()%></td></tr>
						<tr><td width="100">级别</td><td><%=bug.getLevel()%></td></tr>
						<tr><td width="100">频度</td><td><%=bug.getRate()%></td></tr>
						<tr><td width="100">提交人</td><td><%=bug.getCommitterName()%></td></tr>
						<tr><td width="100">提交时间</td><td><%=bug.getCommitTime()%></td></tr>
						<tr><td width="100">修复人</td><td><%=bug.getFixerName()%></td></tr>
						<tr><td width="100">测试人</td><td><%=bug.getTesterName()%></td></tr>
						<tr><td width="100">截图</td><td><img alt="" src="${pageContext.request.contextPath}/sem/bug/image/<%=bug.getId()%>" width=500 height=300></td></tr>
					</table>
				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<% if ("fix".equals(bug.getCurrentNode()) && u.getStaffIds().equals(bug.getFixerId())) { %>
			<div class="panel panel-default">
				<div class="panel-heading">故障修复</div>
				<div class="panel-body">
					<form role="form" id="bugBugFixForm" class="form-horizontal"
						action="${pageContext.request.contextPath}/sem/bug/fix"
						method="post" enctype="multipart/form-data">
						<input type="hidden" name="id" value="<%=bug.getId()%>">
						
						<div class="form-group">
							<label class="col-sm-2 control-label">修复说明</label>
							<div class="col-sm-10">
								<input class="form-control" placeholder="请输入修复说明"
									name="fixRemark">
							</div>
						</div>
						
						<div class="form-group">
                            <label class="col-sm-2 control-label">是否故障</label>
                            <div class="radio col-sm-10">
                                <label>
                                    <input type="radio" name="confirmBug" value="true">是
                                </label>
                            </div>
                            <label class="col-sm-2 control-label">-</label>
                            <div class="radio col-sm-10">
                                <label>
                                    <input type="radio" name="confirmBug" value="false">否
                                </label>
                            </div>
                        </div>
						
						<div class="form-group">
                            <label class="col-sm-2 control-label">修复版本</label>
                            <select class="col-sm-10 form-control" name="fixVersionId">
                            <% for (int i = 0; i < versions.size(); i ++) {
                            	BugVersionDto ver = versions.get(i);
							%>
                                <option value="<%=ver.getId()%>" <%=(i==0)?"selected='selected'":""%>><%=ver.getNo()%></option>
                            <% } %>
                            </select>
                        </div>
						
						<div class="form-group">
							<div class="col-sm-2"></div>
							<div class="col-sm-10">
								<button type="submit" class="btn btn-primary">提交</button>
								<button type="reset" class="btn btn-default">重置</button>
								<button type="button" class="btn btn-warning"
									onclick="location.href='${pageContext.request.contextPath}/'">返回</button>
							</div>
						</div>
					</form>
				
				</div>
			</div>
			<% } %>
			<% if ("test".equals(bug.getCurrentNode()) && u.getStaffIds().equals(bug.getTesterId())) { %>
			<div class="panel panel-default">
				<div class="panel-heading">测试验证</div>
				<div class="panel-body">
					<form role="form" id="bugBugTestForm" class="form-horizontal"
						action="${pageContext.request.contextPath}/sem/bug/test"
						method="post" enctype="multipart/form-data">
						<input type="hidden" name="id" value="<%=bug.getId()%>">
						
						<div class="form-group">
							<label class="col-sm-2 control-label">测试说明</label>
							<div class="col-sm-10">
								<input class="form-control" placeholder="请输入测试说明"
									name="restRemark">
							</div>
						</div>
						
						<div class="form-group">
                            <label class="col-sm-2 control-label">是否通过</label>
                            <div class="radio col-sm-10">
                                <label>
                                    <input type="radio" name="isOk" value="true">是
                                </label>
                            </div>
                            <label class="col-sm-2 control-label">-</label>
                            <div class="radio col-sm-10">
                                <label>
                                    <input type="radio" name="isOk" value="false">否
                                </label>
                            </div>
                        </div>
						
						<div class="form-group">
                            <label class="col-sm-2 control-label">测试版本</label>
                            <select class="col-sm-10 form-control" name="testVersionId">
                            <% for (int i = 0; i < versions.size(); i ++) {
                            	BugVersionDto ver = versions.get(i);
							%>
                                <option value="<%=ver.getId()%>" <%=(i==0)?"selected='selected'":""%>><%=ver.getNo()%></option>
                            <% } %>
                            </select>
                        </div>
						
						<div class="form-group">
							<div class="col-sm-2"></div>
							<div class="col-sm-10">
								<button type="submit" class="btn btn-primary">提交</button>
								<button type="reset" class="btn btn-default">重置</button>
								<button type="button" class="btn btn-warning"
									onclick="location.href='${pageContext.request.contextPath}/'">返回</button>
							</div>
						</div>
					</form>
				
				</div>
			</div>
			<% } %>
		</div>
	</div>
	<div class="row">
		<div class="col-lg-12">
			<div class="panel panel-default">
				<div class="panel-heading">故障日志</div>
				<div class="panel-body">
					<table>
						<tr>
							<th width="50">提交人</th>
							<th width="50">节点</th>
							<th width="200">时间</th>
							<th>操作</th>
						</tr>
						<% for (BugLogDto log : bug.getLogs()) { %>
						<tr>
							<td width="100"><%=log.getProcesserName()%></td>
							<td width="100"><%=log.getNode()%></td>
							<td width="200"><%=log.getProcessTime()%></td>
							<td>
								<input type="hidden" value="<%=log.getId()%>">
								<button class="btn btn-primary btn-xs">查看</button>
							</td>
						</tr>
						<% } %>
					</table>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
	$(document).ready(function () {
    	// 设置各字段的验证规则
    	var fields = {};
    		   	    		   	    	
  		// 将验证规则应用到表单的字段中
		$('#bugBugCreateForm').bootstrapValidator({
            // 默认错误消息
			message: '输入值不合法',
			// 设置验证成功或者失败的图标
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            // 设置不同字段的验证规则和错误信息
            fields: fields
        });
  		$('table button.btn-xs').click (function () {
  			var logId = $(this).prev().val();
  			// 动态创建bugLogDialog的div
  			$('#bugLogDialog').remove();
        	$('body').append ('<div class="modal fade" id="bugLogDialog" tabindex="-1" role="dialog" aria-labelledby="semBugSelectorModalLabel"></div>');
        	// 通过ajax加载对话框的内容
        	$('#bugLogDialog').load ("${pageContext.request.contextPath}/sem/bug/log?id=" + logId, function () {
        		$('#bugLogDialog').modal('show');
        	});
        	
  		});
    });	
	</script>
</div>